<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set value="${pageContext.request.contextPath}" var="path" scope="page"/>
<html>
<head>
  <title>我的收藏</title>
</head>

<body>
<div class="myaccount">
  <div class="row">
    <div class="ucenter">
      <div class="ucenter-info mt10">
        <div class="info-title">
          <h5>我的收藏</h5>
        </div>
        <div id="show3" class="info"></div>
      </div>
    </div>
  </div>
</div>
</body>

<script>
  //时间戳转换为时间
  function timestampToTime(timestamp) {
    var date = new Date(timestamp);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
    var Y = date.getFullYear() + '-';
    var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
    var D = date.getDate() + ' ';
    var h = date.getHours() + ':';
    var m = date.getMinutes() + ':';
    var s = date.getSeconds();
    return Y+M+D+h+m+s;
  }

  $(document).ready(function() {
    var user="<%=session.getAttribute("user")%>";
    var uid = ${user.id};
    var href = "";

    //获取收藏
    $.ajax({
      url: "/action/getCollection",
      type: "post",
      data: {uid:uid},
      dataType: "json",
      success: function(result) {
        var str = "";
        for(var key in result){
          for(i=0; i<result[key].length; i++) {
            console.log(result[key][i]);
            href = result[key][i].item.id;
            str += '<div class="info">';
            str += '    <ul class="info-img">';
            str += '	<a href="${path}/productDetail?id='+ href +'">';
            str += '      <li style="margin-top: 10%;"><img src="${path}/backstage/images/' + result[key][i].item.picUrl + '" class="avatar" style="height: 103px;"/></li>';
            str += '	</a>';
            str += '    </ul>';
            str += '    <div class="info-main" style="border-bottom: 1px solid #ebebeb;margin-bottom: 1%;">';
            str += '      <div class="row">';
            str += '	<a href="${path}/productDetail?id='+ href +'">';
            str += '        <label>';
            str += '          商品名：</label>' + result[key][i].item.itemName + '' + '</a></div>';
            str += '      <div class="row">';
            str += '        <label>';
            str += '          价格：</label>' + result[key][i].item.price + '</div>';
            str += '      <div class="row">';
            str += '        <label>';
            str += '          描述：</label>' + result[key][i].item.description + '</div>';
            str += '      <div class="row">';
            str += '        <label>';
            str += '          如何使用：</label>' + result[key][i].item.howUse +'</div>';
            str += '      <div class="row">';
            str += '        <label>';
            str += '          收藏时间：</label>' + timestampToTime(result[key][i].item.createDate) + '</div>';
            str += '    </div>';
            str += '</div>';
          }
        }
        $('#show3').html(str);
      }
    });
  });
</script>

</html>
